import type {LoginDto} from '@/service/entity/LoginDto';
import type {DataBox} from '@/service/entity/DataBox';
import fetchData from '@/utils/fetchData';
import type {UserMo} from "@/service/entity/UserMo";
import type {GetListArgs} from "@/service/entity/GetListArgs";

const proxy = async (path: string, data?: any) => {
    return await fetchData('/srv-auth/admin/user/' + path, data)
}

export interface LoginArgs {
    uname: string
    passwd: string
    uuid: string
    code: string
}

export const login = async (args: LoginArgs): Promise<LoginDto> => {
    return await proxy('login', args)
}

export const getCaptcha = async (): Promise<{
    codeImageBase64: string
    uuid: string
}> => {
    return await proxy('getCaptcha')
}

export const delUser = async (uid: any): Promise<DataBox> => {
    return await proxy('delUser', {uid})
}

export const getAllUserList = async (args: GetListArgs): Promise<{
    arr: UserMo[]
    total: number
}> => {
    return await proxy('getAllUserList', args)
}

export const setAdmin = async (uid: any): Promise<DataBox> => {
    return await proxy('setAdmin', {uid})
}

export const superAdminDelUser = async (uid: any): Promise<DataBox> => {
    return await proxy('superAdminDelUser', {uid})
}

export const createVirtualUser = async (uname: string, passwd: string, name: string): Promise<DataBox> => {
    return await proxy('createVirtualUser', {uname, passwd, name})
}

export const createPerpetualToken = async (uid: any, appId: any): Promise<String> => {
    return await (await proxy(`createPerpetualToken/${appId}/${uid}`))?.data
}


